package com.example.proyyj.Controller;


import com.example.proyyj.Entity.ResultEntity;
import com.example.proyyj.Entity.Video;
import com.example.proyyj.Service.VideoService;
import com.example.proyyj.Util.JSONTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/Video/")
public class VideoController {
    ResultEntity resultEntity=null;
    @Resource
    VideoService ness;


    @GetMapping("viodelist")
    private  String Viodes(){
        try {
            resultEntity=new ResultEntity();
            List<Video> list= ness.videolist();
            if(list!=null){
                resultEntity.setCode("0");
                resultEntity.setMsg("查询成功");
                resultEntity.setData(list);
            }
        }catch (Exception e){
            e.printStackTrace();
            resultEntity.setCode("99999");
            resultEntity.setMsg("查询失败");
        }
        return  JSONTool.getJsonTool().toJson(resultEntity);
    }

    @GetMapping("videoid")
    private  String videoid(@RequestParam("id") int id){
        try {
            resultEntity=new ResultEntity();
            Video video= ness.videoid(id);
            if (video!=null){
                resultEntity.setCode("0");
                resultEntity.setMsg("查询成功");
                resultEntity.setData(video);
            }else {
                resultEntity.setCode("1");
                resultEntity.setMsg("失败");
            }
        }catch (Exception e){
            e.printStackTrace();
            resultEntity.setCode("99999");
            resultEntity.setMsg("查询失败");
        }
        return  JSONTool.getJsonTool().toJson(resultEntity);
    }

}
